package com.stat;

import java.util.HashMap;

import com.ability.CharacterAbility;
import com.charactersheet.sheet.CharacterSheet;
import com.info.BonusInfo;
import com.info.BonusTypeEnum;
import com.info.SkillInfo;

public class CharacterSkill {

	
	private static final HashMap<String, CharacterSkill> SKILL_MAP = new HashMap<String, CharacterSkill>();
	
	public static CharacterSkill getCharacterSkill(String playerName){
		if (!SKILL_MAP.containsKey(playerName)){
			return null;
		}
		return SKILL_MAP.get(playerName);
	}
	
	public static CharacterSkill createCharacterSkill(CharacterSheet sheet, String playerName){
		return SKILL_MAP.put(playerName, new CharacterSkill(sheet));
	}
	
	private HashMap<SkillInfo, Integer> skillSet;
	private CharacterSheet sheet;
	
	private CharacterSkill(CharacterSheet sheet){
		skillSet = new HashMap<SkillInfo, Integer>();
		this.sheet = sheet;
	}
	
	public void addPoint(SkillInfo skill){
		if (skillSet.containsKey(skill)){
			skillSet.put(skill, skillSet.get(skill) + 1);
		}
	}
	
	public int getSkillTotal(SkillInfo skill){
		int total = skillSet.get(skill);
		total += sheet.getAbility().getAbilityModifiers()[skill.getAbilityType().ordinal()];
		if (sheet.getClasses().containClassSkill(skill)){
			total += (skillSet.get(skill) > 0 ? 3 : 0);
		}
		BonusInfo bonus = new BonusInfo();
		bonus.addBonus(sheet.getEquip().getTotalBonus(BonusTypeEnum.SKILL_BONUS, skill.getName()));
		
		return total + bonus.getBonusTotal();
	}
	
	public int[] getSkillTotals(CharacterAbility ability){
		int totals[] = new int[skillSet.size()];
		int counter = 0;
		for (SkillInfo s : skillSet.keySet()){
			totals[counter] = getSkillTotal(s);
			counter++;
		}
		return totals;
	}
}
